package servlet.Student;

import bean.Student;
import dao.impl.StudentIDaoImp;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet("/student/search")
public class StudentSearch extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");//请求编码
        resp.setContentType("text/html;charset=utf-8");//响应编码
        String sname = req.getParameter("sname");
        StudentIDaoImp dao = new StudentIDaoImp();
        HttpSession session = req.getSession();
        List<Student> studentsList = dao.getStudentsByName(sname);
        System.out.println(studentsList);
        session.setAttribute("studentList", studentsList);
        resp.sendRedirect("/student/showStudent.jsp");
    }
}
